"use client"; import { ServiceTypes } from "@/api/customservice"; import { lredPacketApi, redPacketApi } from "@/api/promo"; import RedPacketModal, { RedPacketModalProps } from "@/components/Box/RedPacketModal"; import { Link } from "@/i18n"; import { useGlobalNoticeStore } from "@/stores/useGlobalNoticeStore"; import { useSocialStore } from "@/stores/useSocials"; import { getToken } from "@/utils/Cookies"; import { useRequest } from "ahooks"; import { Badge } from "antd-mobile"; import { useTranslations } from "next-intl"; import { FC, useEffect, useRef, useState } from "react"; interface Props { services: ServiceTypes[]; socials: ServiceTypes[]; } const ServiceWidget: FC = (props) => { const token = getToken(); const [packets, setPackets] = useState([]); const { services, socials } = props; const defaultService = services.find((item) => item.is_suspend === 1); const newServices = services.filter((item) => item.is_suspend !== 1); const setSocials = useSocialStore((state) => state.setSocials); const RedPacketModalRef = useRef(null); useEffect(() => { // 数据存储,侧边栏使用 setSocials(socials); }, []); const t = useTranslations("HomePage"); const { unread } = useGlobalNoticeStore((state) => ({ unread: state.unread, })); const getRedPacketInfo = async () => { try { let redPacketInfo: any; let actList: any = []; if (token) { redPacketInfo = await lredPacketApi(); actList = redPacketInfo.data?.red_packets || []; } else { redPacketInfo = await redPacketApi(); actList = redPacketInfo.data || []; } // 是否有已开始但是没领过的红包 let isHasStartAct = actList.filter((aItem: any) => { return aItem.is_start && !aItem.is_receive; }); console.log(`🚀🚀🚀🚀🚀-> in Service.tsx on 53`, isHasStartAct); setPackets(isHasStartAct); } catch (error) { console.log("redPacketInfo===>error:", error); } }; // 红包雨轮询 useRequest(getRedPacketInfo, { pollingInterval: 180000, pollingErrorRetryCount: 1, pollingWhenHidden: false, onSuccess: (data) => { console.log("data", data); }, }); return ( <> {/* 红包雨icon */} {packets.map((item, index) => { return (
{ RedPacketModalRef.current?.onOpen(index); }} />
); })} {/* 红包弹窗 */} {/*{isShowRedPacket && (*/} {/* {*/} {/* setIsShowRedPacket(false);*/} {/* }}*/} {/* />*/} {/*)}*/} {defaultService && ( )}
= 5 ? 5 : newServices.length}`}> {newServices.map((service, index) => { return ( ); })}
{t("Service")}
{/*share*/}
{t("Share")}
= 5 ? 5 : socials.length}`}> {socials.map((service, index) => { return ( ); })}
); }; export default ServiceWidget;